package cjyyp.day02;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class wait_notify {
    static Object object=new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                log.debug("准备执行t1的方法.....");
                synchronized (object){
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    log.debug("t1的方法执行完！");
                }
            }
        });

        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                log.debug("准备执行t2的方法.....");
                synchronized (object){
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    log.debug("t2的方法执行完！");
                }
            }
        });

        t1.start();
        t2.start();
        //主线程睡3s
        Thread.sleep(2000L);
        synchronized (object){
            //随机唤醒一个线程
           // object.notify();
            //唤醒全部
            object.notifyAll();
        }


    }
}
